<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/pagelet/page-includes.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
</head>
<body class="hold-transition skin-blue sidebar-mini">
			<section class="content" style="align-content: center">
<!-- 内容开始 -->
				<div>
					<form class="form-horizontal" style="align-content: center">
						<div class="box-body">
							<div class="row rowStyle" style="height: 200px">
								<div class="col-xs-4 bs-valid">
									<label for="headImg">头像: </label>
									<div style="width: 152px;height: 152px; border: 1px solid #d2d6de;">
										<img id="showheadImg" style="width: 150px;height: 150px;" src="${sysUser.headImgUrl }" />
									</div>
								</div>
								<div class="col-xs-8 bs-valid">
									<label>&nbsp;</label>
									<div id="picker">选择文件</div>
									<div id="showId"></div>
									<input type="hidden" name="headImg" id="headImg" value="${sysUser.headImg }" />
								</div>
							</div>
							<div class="row rowStyle">
								<div class="col-xs-4 bs-valid">
									<label for="userName">用户名称: </label>
									<input type="text" class="form-control" id="userName" name="userName" value="${sysUser.userName }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="status">用户状态: </label>
									<asone:tag type="select" table="t_sys_dict" where="dict_code='asone_sysUser_status'" fieldName="dict_remark" fieldValue="dict_value" top="false" checkValue="${sysUser.status }" tagAttr="class='form-control' id='status' name='status' "></asone:tag>
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="realName">真实姓名: </label>
									<input type="text" class="form-control" id="realName" name="realName" value="${sysUser.realName }">
								</div>
							</div>
							<div class="row rowStyle">
								<div class="col-xs-4 bs-valid">
									<label for="orgName">所属机构: </label>
									<input type="text" class="form-control" onclick="showMenu('orgName');" id="orgName" name="orgName" value="${sysUser.orgName }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="orgCode">所属机构编码: </label>
									<input type="text" class="form-control" readonly="readonly" id="orgCode" name="orgCode" value="${sysUser.orgCode }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="orgCode">用户角色: </label>
									<asone:tag type="select" table="t_sys_group" where="group_status='1'" fieldName="group_name" fieldValue="id" top="false" checkValue="${sysUser.sysGroup.id }" tagAttr="class='form-control' id='sysGroup.id' name='sysGroup.id' "></asone:tag>
								</div>
							</div>
							<div class="row rowStyle">
								<div class="col-xs-4 bs-valid">
									<label for="tel">手机号码: </label>
									<input type="text" class="form-control" id="tel" name="tel" value="${sysUser.tel }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="email">电子邮箱: </label>
									<input type="text" class="form-control" id="email" name="email" value="${sysUser.email }">
								</div>
							</div>
						</div>
						<div class="box-footer text-center">
							<input type="hidden" name="id" id="id" value="${sysUser.id }" />
							<button type="button" class="btn btn-primary saveBtn" onclick="save()">保存</button>
						</div>
					</form>
				</div>
				<div id="treeDiv" class="treeDiv" style="display:none; position: absolute;">
					<ul id="treeUl" class="ztree" style="margin-top:0; width:160px;"></ul>
				</div>
<!-- 内容结束 -->
			</section>
</body>

<script type="text/javascript">

var index = parent.layer.getFrameIndex(window.name);

onload = function(){
	
	//机构树
	var setting = {
		view: {
			selectedMulti: false
		},
		async: {
			enable: true,
			url:"${webroot}/sysorg/getjsondata",
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onClickTree
		}
	};
	$.fn.zTree.init($("#treeUl"), setting);
	
	
	
	//添加校验表单
	$('.form-horizontal').bootstrapValidator({
		message: '输入错误',
		feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
        	userName : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^[0-9A-Za-z]{4,20}$/,message: '用户名名为4~20个字符'}
        		}
        	},
        	realName : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
        			regexp: {regexp: /^[a-zA-Z\u4e00-\u9fa5]{1,100}$/, message: '真实姓名为1~100个字符，不能包含特殊字符'}
        		}
        	},
        	orgCode : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^[0-9]{12}$/,message: '机构编码为12个数字'}
        		}
        	},
        	orgName : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^[a-zA-Z0-9_\u4e00-\u9fa5]{1,200}$/, message: '机构名称为1~200个字符，不能包含特殊字符'}
        		}
        	},
        	tel : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^1[3|4|5|8][0-9]\d{4,8}$/, message: '请输入正确的手机号码'}
        		}
        	},
        	email : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, message: '请输入正确的电子邮箱'}
        		}
        	}
        }
	})
	app.upload.init(
			"picker",
			app.upload.type.image(), 
			"showId", 
			function(data){
				if(data.success){
	        		$("#showheadImg").attr({"src":data.content.fileUrl});
	            	$("#headImg").val(data.content.fileId);
	        	} else {
	        		alert("失败");
	        	}
			}, function(data){
				alert("失败");
			}
	)
}


function onClickTree(e, treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj("treeUl"),
	nodes = zTree.getSelectedNodes(),
	name = "";
	value = "";
	nodes.sort(function compare(a,b){return a.id-b.id;});
	for (var i=0, l=nodes.length; i<l; i++) {
		value += nodes[i].id + ",";
		name += nodes[i].name + ",";
	}
	if (value.length > 0 ) value = value.substring(0, value.length-1);
	if (name.length > 0 ) name = name.substring(0, name.length-1);
	
	$("#orgName").val(name);
	$("#orgCode").val(value);
	
	hideMenu();
}


function save() {
	$('.form-horizontal').bootstrapValidator('validate');
	if(!$('.form-horizontal').data('bootstrapValidator').isValid()) return;
	var id = "${sysUser.id}";
	var flag = "";
	if(id != null && id!= ""){
		flag = "UPDATE";
	}
	$.ajax({
		type: "POST",
		url: webroot + "/sysuser/modify?showtype=" + flag,
		data:$('.form-horizontal').serialize(),
		dataType: "json",
		success: function(resp){
			if(resp.success){
				app.print.success("保存成功!", index,null)
			} else {
				app.print.error(resp.message, null, null);
			}
		}
	});
}


</script>

</html>
